package cn.com.commons.result;

import java.io.Serializable;

/**
 * 一个抽象的<code>Result</code>，完成了<code>Result<code>的所有实现。
 * 
 * @param <T>
 * @author Microbun 2012-2-9下午10:43:09
 * @since 1.0
 * @version $Id: AbstractResult.java 76 2012-02-29 10:10:23Z microbun $
 * @see {@link Result}
 */
public abstract class AbstractResult<T> implements Result<T>, Serializable {

	private static final long serialVersionUID = -6390123895432052509L;

	protected boolean state;

	protected T data;

	/**
	 * 构造一个默认的<code>Result</code>
	 */
	public AbstractResult() {
	}

	/**
	 * 构造一个指定包含指定内容的<code>Result</code>
	 * 
	 * @param state
	 *            <code>Result</code>的初始化状态
	 * @param data
	 *            指定的数据
	 */
	public AbstractResult(boolean state, T data) {
		this.state = state;
		this.data = data;
	}

	@Override
	public void setSucceed(boolean state) {
		this.state = state;
	}

	/**
	 * 将指定数据加入到<code>Result</code>
	 * 
	 * @param data
	 *            要添加的数据
	 */
	@Override
	public void setData(T data) {
		this.data = data;
	}

	@Override
	public boolean isSucceed() {
		return state;
	}

	@Override
	public T getData() {
		return data;
	}

}
